package spring.JdbcDemo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.testng.annotations.Test;

import java.util.List;

@Repository("userDao")
@Transactional
public class UserDao {
    @Autowired
    @Qualifier("jdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    public void selectUserById() throws Exception {
        String sql  = "select * from user; ";
        RowMapper<User> rowMapper=new BeanPropertyRowMapper<User>(User.class);
        List<User> list = jdbcTemplate.query(sql,rowMapper);
        for(User user: list) {
            System.out.print(user + " ");
        }
    }
}
